package com.lemon.smartsafety.view.banner;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.bigkoo.convenientbanner.holder.Holder;
import com.bumptech.glide.Glide;
import com.lemon.android.http.HttpUtils;
import com.lemon.smartsafety.R;
import com.lemon.smartsafety.utils.app.SharedPreferencesServer;
import com.lemon.smartsafety.utils.common.LoggerHelper;
import com.lemon.safecloud.greendao.PlayView;

/**
 * Created by Sai on 15/8/4.
 * 网络图片加载例子
 */
public class NetworkImageHolderView implements Holder<PlayView> {
    private LoggerHelper loggerHelper = new LoggerHelper(NetworkImageHolderView.class);
    private ImageView               imageView;
    private TextView                textView;
    private SharedPreferencesServer mshaSharedPreferencesServer;
    @Override
    public View createView(Context context) {
        //你可以通过layout文件来创建，也可以像我一样用代码创建，不一定是Image，任何控件都可以进行翻页
        View parentView = LayoutInflater.from(context).inflate(R.layout.item_banner_sub_view, null);
        imageView = (ImageView) parentView.findViewById(R.id.imageView);
//        imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
        textView = (TextView) parentView.findViewById(R.id.textView);
        return parentView;
    }

    @Override
    public void UpdateUI(Context context, int position, PlayView data) {
        mshaSharedPreferencesServer = new SharedPreferencesServer(context);
        textView.setText(data.getTitle());
        imageView.setImageResource(R.mipmap.new_ad_logo);
        String url = HttpUtils.formatFilesUrl(data.getUrl(), mshaSharedPreferencesServer.getFilesUrl());
        Glide.with(context).load(url).placeholder(R.mipmap.new_ad_logo).into(imageView);
    }
}
